#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File    :   recursion.py
@Time    :   2024/12/28 00:17:24
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''

# 利用递归函数移动汉诺塔:
# import sys
# print(sys.getrecursionlimit())#默认1000
# sys.setrecursionlimit(100)  # 将递归的深度修改的大一些,例如这里设置为十万

# def move(n, a, b, c):
#     if n == 1:
#         print('move', a, '-->', c)
#     else:
#         move(n-1, a, c, b)
#         move(1, a, b, c)
#         move(n-1, b, a, c)

# move(5, 'A', 'B', 'C')


def L_move(n: int, La=None, Lb=None, Lc=None, N=None):
    if La is None:  # 初始化列表并打印
        N = n
        La = {'a': list(range(1, n+1))}
        Lb = {'b': []}
        Lc = {'c': []}
        # print(La, Lb, Lc, end=' ')
        print({**La, **Lb, **Lc})
    if n == 1:  # 只剩最后一块时的移动
        m = La[list(La.keys())[0]].pop(0)
        Lc[list(Lc.keys())[0]].insert(0, m)
        print(list(La.keys())[0], '------', m, '------>', list(Lc.keys())[0])
        sort_print({**La, **Lb, **Lc}, N)
    else:
        L_move(n-1, La, Lc, Lb, N)  # 只剩2块未移动到C，小的先移到B
        L_move(1, La, Lb, Lc, N)  # 大的移动到C
        L_move(n-1, Lb, La, Lc, N)  # 小的从B移动到C


def sort_print(args: dict, n=None):
    # kList = list(args.keys())
    # kList.sort()
    # for k in kList:
    #     L = len(args[k])
    #     need_L = (n-L)*3
    #     print(f'{k}: {args[k]}',  end=' ' *
    #           (need_L-2 if L == 0 else need_L))
    sort_List = sorted(args.items())#把字典按Key排序并返回列表
    for k, v in sort_List:
        L = len(v)
        need_L = (n-L)*3
        print(f'{k}: {v}',  end=' ' *
              (need_L-2 if L == 0 else need_L))
    print()


if __name__ == '__main__':
    L_move(3)
    # LL = list(range(1, 4))
    # print(LL.remove(1))
    # LL.insert(0, 1)
    # print(LL)
    # print([].__class__)

    # a = {'a': list(range(1, 4))}
    # b = {'b': list(range(1, 5))}
    # c = {'c': list(range(1, 6))}
    # abc = {**a, **c, **b}
    # print(a[list(a.keys())[0]].pop(0))
    # print(a)
    # a[list(a.keys())[0]].insert(0, 5)
    # print(a)
    # abcKList = list(abc.keys())
    # print(abcKList)
    # abcKList.sort()
    # print(abcKList)
